
let host = "http://www.bufantec.com";

// axios.get(url, data)/.post

let obj = {
    get (url, data) {
        return new Promise( (resolve, reject) => {
            wx.request({
                url: host + url,
                data,
                success (res) {
                    resolve(res);
                },
                fail (err) {
                    reject(err)
                }
            });
        })
    },
    post (url, data) {
        return new Promise((resolve, reject) => {
            wx.request({
              url: host + url,
              data,
              method: 'POST',
              header: {
                'content-type': "application/x-www-form-urlencoded" 
              },
              success (res) {
                  resolve(res);
              },
              fail (err) {
                  reject(err)
              }
            })
        })
    }
}

/**
 * 封装目标
 * function home (data) {
 *  return http({
 *      methods: ,
 *      url: ''
 *      data
 * })
 * }
 * 
 */

 function http (data) {
     if (data.method.toLowerCase() == 'post') {
         return obj.post(data.url, data.data);
     } else {
        return obj.get(data.url, data.data);
     }
 }

export { obj as http };
export default http;